import 'package:base_plugin/base_plugin.dart';
import 'package:finance_app/generated/l10n.dart';
import 'package:finance_app/src/common/app_colors.dart';
import 'package:finance_app/src/common/app_spaces.dart';
import 'package:finance_app/src/common/config.dart';
import 'package:finance_app/src/utils/cash_utils.dart';
import 'package:finance_app/src/widgets/form/value_select_form.dart';
import 'package:finance_app/src/widgets/select/normal_check_box.dart';
import 'package:finance_app/src/widgets/switch/normal_switch.dart';
import 'package:finance_app/src/widgets/wrapper/normal_form_wrapper.dart';
import 'package:flutter/material.dart';

import 'form_edit_status_inherited_widget.dart';
import 'icon_currency_price_input_form.dart';

class BuyOrSellForm extends StatelessWidget {
  final bool isCheck;
  final VoidCallback onChangeCheck;
  final String title;
  final VoidCallback onChangeUnt;
  final String unit;
  final TextEditingController controller;
  final FocusNode focusNode;
  final String gstRate;
  final bool isCheckInclusive;
  final VoidCallback onChangeCheckInclusive;
  final VoidCallback onChangeGstRate;

  const BuyOrSellForm(
      {Key key,
      this.isCheck,
      this.onChangeCheckInclusive,
      this.onChangeGstRate,
      this.onChangeCheck,
      this.title,
      this.onChangeUnt,
      this.unit,
      this.gstRate,
      this.isCheckInclusive,
      this.controller,
      this.focusNode})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    bool isEnable = FormEditStatusInheritedWidget.ofEnable(context);
    if (isEnable) {
      return Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          NormalFormWrapper(
            child: PressedOpacityButton(
              onPressed: onChangeCheck,
              child: NormalSwitch(
                title: title,
                isSelect: isCheck,
              ),
            ),
          ),
          if (isCheck)
            Column(
              children: [
                AppSpaces.grayH05,
                IconCurrencyPriceInputForm(
                  controller: controller,
                  focusNode: focusNode,
                  currency: unit,
                  leftPadding: getDp(15),
                  rightPadding: getDp(10),
                  onChangeCurrency: onChangeUnt,
                ),
                Visibility(
                    visible: Config.currentCompany.enableGst == 1,
                    child: Column(
                      children: [
                        SizedBox(
                          width: MediaQuery.of(context).size.width,
                          child: ValueSelectForm(
                            title: S.current.gst_rate,
                            value: gstRate,
                            onTap: onChangeGstRate,
                          ),
                        ),
                        NormalFormWrapper(
                          child: PressedOpacityButton(
                            onPressed: onChangeCheckInclusive,
                            child: NormalCheckBox(
                              title: S.current.price_inclusive_of_tax,
                              minWidth: MediaQuery.of(context).size.width,
                              isSelect: isCheckInclusive,
                            ),
                          ),
                        )
                      ],
                    )),
              ],
            )
        ],
      );
    } else {
      return NormalFormWrapper(
        topPadding: getDp(13),
        bottomPadding: getDp(13),
        leftPadding: getDp(35),
        rightPadding: getDp(35),
        child: Row(
          children: [
            Expanded(
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Padding(
                    padding: EdgeInsets.only(
                      bottom: getDp(10),
                    ),
                    child: Text(
                      title,
                      style: TextStyle(
                        color: aceDarkGrayColor,
                        fontSize: getSp(14),
                        fontWeight: FontWeight.w400,
                        height: 1,
                      ),
                    ),
                  ),
                  Text(
                    '$unit ${CashUtils.formatCashAmountString(controller.text)}',
                    style: FormEditStatusInheritedWidget.ofStyle(context),
                  )
                ],
              ),
            ),
            Column(
              crossAxisAlignment: CrossAxisAlignment.center,
              children: [
                Padding(
                  padding: EdgeInsets.only(
                    bottom: getDp(10),
                  ),
                  child: Text(
                    S.current.gst_rate,
                    style: TextStyle(
                      color: aceDarkGrayColor,
                      fontSize: getSp(14),
                      fontWeight: FontWeight.w400,
                      height: 1,
                    ),
                  ),
                ),
                Text(
                  '$gstRate',
                  style: FormEditStatusInheritedWidget.ofStyle(context),
                )
              ],
            ),
            SizedBox(
              width: getDp(16),
            ),
            Column(
              crossAxisAlignment: CrossAxisAlignment.end,
              children: [
                Padding(
                  padding: EdgeInsets.only(
                    bottom: getDp(10),
                  ),
                  child: Text(
                    S.current.tax_inclusive,
                    style: TextStyle(
                      color: aceDarkGrayColor,
                      fontSize: getSp(14),
                      fontWeight: FontWeight.w400,
                      height: 1,
                    ),
                  ),
                ),
                Text(
                  '${isCheckInclusive ? S.current.yes : S.current.no}',
                  style: FormEditStatusInheritedWidget.ofStyle(context),
                )
              ],
            ),
          ],
        ),
      );
    }
  }
}
